**********************
**********************
*Replication Code for

*Hansen, Eric R., and Connor Mautner. "Job Talk: Candidate Gender and Presentation of Prior Experience in Television Ads in the US
." Politics & Gender.

*Compiled by Eric Hansen, 8/20/24 (ehansen4@luc.edu)
*Using StataNow 18.5 SE
**********************
**********************

**************
**Note on Reproducibility: 
**************
*Estimates obtained with this code are slightly noisy despite setting a seed for reproducibility. 
*On repeated iterations, this code will produce coefficient estimates that closely approximate the reported coefficients and maintain the direction and statistical significance reported in the manuscript.
*The deviations away from the reported coefficient are rarely more than 5% of the absolute value of the reported coefficient. (E.g. a reported coefficient of 3 may appear between 2.85 and 3.15.)
*For the main results table below (Table B1), we note the observed range of coefficient estimates for the principal independent variable.

*set seed
set seed 374184546


**************
*Load and merge data
**************
*set working directory. Make sure Replication Data and Wesleyan Media Project data are in the same folder. 
*cd [filepath]

*to merge
use "wmp-downballot-2018-v1.0.dta"
gen id = _n
merge 1:1 id using "Publication Files/Hansen_Mautner_Replication_Data.dta"
keep if _merge==3



***********
*Recode variables and clean data
***********
encode categorystate, gen(stateid)
encode party, gen(partycode)
recode partycode (1=1) (*=0), gen(democrat)
recode partycode (4=1) (*=0), gen(republican)
encode sponsorcmag, gen(candid)
*drop joint ads from multiple candidates
gen jointad = 0
replace jointad = 1 if incumbent == .
drop if jointad == 1
gen promote = 0
replace promote = 1 if ad_tone==2
gen polexp = 0
replace polexp = 1 if incumbent==1 
replace polexp = 1 if prior==1
gen contrib = contributions/100000
sort candid
by candid: generate numberads = _n
gen cost = est_cost/1000
encode raceethnicity, gen(candrace)
recode candrace (1/6=0) (7=1) (*=.), gen(white)
recode candrace (1=0) (2=1) (3/7=0) (*=.), gen(black)
recode candrace (1/2=0) (3=1) (4/7=0) (*=.), gen(latino)
*distinguish general, primary, special/runoff ads
encode election, gen(electiontype)
recode electiontype (1=0)(3=1) (*=2), gen(electtype)

*Label variables
label variable self_occ_mention "Work Experience"
label variable self_politician "Political Experience"
label variable female "Woman Sponsor" 
label variable incumbent "Incumbent"
label variable democrat "Democrat"
label variable l "Ad Length"
label variable polexp "Prior Office"
label variable promote "Promotional Ad"
label variable contrib "Campaign Contributions in /$100,000"
label variable numberads "Ad Volume"
label variable cost "Estimated Ad Cost in \$1000"
label variable white "White"
label variable black "Black"
label variable latino "Latino"
label define electtype 0 "General" 1 "Primary" 2 "Special or Runoff"
label values electtype electtype
label variable electtype "Type of Election"
*note electtype: 0=General, 1=Primary, 2=Special/Other

***********
*Findings in main manuscript
***********

*frequency of experience mentions -- referenced in text of "Data and Methods" section
gen experience = 0
replace experience = 1 if self_occ_mention==1 | self_politician == 1
tab experience
tab self_occ_mention
tab self_politician
tab self_politician self_occ_mention, col

*gender differences in political experience -- presented in text alongside Figure 1
tab self_politician female if polexp==1, col
ttest self_politician if polexp==1, by(female)

*Figure 1
*Install catplot package if not already installed on your device
*ssc install catplot
recode self_politician (0=1) (1=0), gen(barselfpol)
catplot barselfpol female if polexp==1, percent(female) asyvars stack legend( label(1 "Mention") label(2 "No Mention") pos(6) region(lcolor(black)) rows(1)) graphregion(fcolor(white)) ytitle("% Ads from Experienced Candidates", margin(medsmall)) var2opts( relabel(1 "Men" 2 "Women")) bar(1, color("gs6") lcolor("black")) bar(2, color("white") lcolor("black"))
*descriptives at start of findings section
tab self_politician polexp, col
*note: two folks who advertised political experience w/o elected experience were a city administrator and a legislative aide

*Figure 2
quietly melogit self_politician i.female incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
margins female
marginsplot, recast(scatter) title("") ytitle(P(Mention Political Experience), margin(medium)) xtitle("") xlabel(0 "Men" 1 "Women") yscale(range(0(.2)1)) ylabel(0 0.2 0.4 0.6 0.8 1) xscale(range(-0.5(0.5)1.5)) graphregion(fcolor(white)) ciopts(col(gs4)) plot1opts(color(black))

*gender differences in work experience -- presented in text alongside Figure 3
tab self_occ_mention female, col
ttest self_occ_mention, by(female)

*Figure 3
*ssc install catplot
recode self_occ_mention (0=1) (1=0), gen(barselfocc)
catplot barselfocc female, percent(female) asyvars stack legend( label(1 "Mention") label(2 "No Mention") pos(6) region(lcolor(black)) rows(1)) graphregion(fcolor(white)) ytitle("% Ads", margin(medsmall)) var2opts( relabel(1 "Men" 2 "Women")) bar(1, color("gs6") lcolor("black")) bar(2, color("white") lcolor("black"))

*Figure 4
quietly melogit self_occ_mention i.female incumbent polexp democrat white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid) 
margins female
marginsplot, recast(scatter) title("") ytitle(P(Mention Work Experience), margin(medium)) xtitle("") xlabel(0 "Men" 1 "Women") yscale(range(0(.2)1)) ylabel(0 0.2 0.4 0.6 0.8 1) xscale(range(-0.5(0.5)1.5)) graphregion(fcolor(white)) ciopts(col(gs4)) plot1opts(color(black))

*****************
*Section B of online appendix
*****************

*Table B1
sum self_politician self_occ_mention female incumbent polexp democrat white contrib l promote cost numberads i.electtype 


*Table B2
*These models underlie the figures reported in the main manuscript.
melogit self_politician female incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
melogit self_occ_mention female incumbent polexp democrat white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid)
*Note: On repeated iterations, we have observed coefficients for the "Woman Sponsor" variable between 0.75 and 0.77 in column 1 and between 0.20 and 0.21 in column 2.

*Table B3
melogit self_occ_mention i.female incumbent polexp democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid: , vce(cluster candid) 
melogit self_occ_mention i.female incumbent polexp democrat white contrib l promote cost numberads i.electtype if polexp==0 || candid:, vce(cluster candid) 

*****************
*Section C of online appendix
*****************

*Table C1
preserve
keep if democrat == 1
melogit self_politician i.female incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
melogit self_occ_mention female incumbent polexp democrat white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid)
restore
preserve
keep if republican == 1
melogit self_politician female incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
*occupation
melogit self_occ_mention female incumbent polexp democrat white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid)
restore

*predicted probabilities from Table C1 -- mentioned in text in section c of appendix
preserve
keep if democrat == 1
melogit self_politician i.female incumbent white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
margins female
restore
preserve
keep if republican == 1
melogit self_politician i.female incumbent white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
margins female
restore

*Table C2
preserve
keep if female==1 
*drop independent/third-party
drop if partycode==2 | partycode==3
melogit self_politician democrat incumbent white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
melogit self_occ_mention democrat incumbent polexp white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid)
restore

*predicted probabilites from Table C2 -- discussed briefly at end of section c of appendix
preserve
keep if female==1 
*drop independent/third-party
drop if partycode==2 | partycode==3
melogit self_politician i.democrat incumbent white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
margins democrat
melogit self_occ_mention i.democrat incumbent polexp white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid)
margins democrat
restore

*****************
*Section D of online appendix
*****************

*Table D1
melogit self_politician opp_self_politician opp_occ_mention female incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
melogit self_occ_mention opp_self_politician opp_occ_mention female incumbent polexp democrat white contrib l promote cost numberads i.electtype || candid:, vce(cluster candid)

*****************
*Section E of online appendix
*****************

*Table E1
melogit self_politician i.female##i.incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)

*Figure E1
quietly melogit self_politician i.female##i.incumbent democrat white contrib l promote cost numberads i.electtype if polexp==1 || candid:, vce(cluster candid)
margins, at(female==(0 1) incumbent==(0 1))
marginsplot, recast(scatter) title("") ytitle(P(Mention Political Experience), margin(medium)) xtitle("") xlabel(0 "Men" 1 "Women") yscale(range(0(.2)1)) ylabel(0 0.2 0.4 0.6 0.8 1) xscale(range(-0.5(0.5)1.5)) legend(order(1 2) label(1 "Nonincumbents")) legend(label(2 "Incumbents") pos(6) region(lcolor(black))) graphregion(fcolor(white)) ci1opts(col(gs9)) plot1opts(color(gs9)) ci2opts(col(black)) plot2opts(color(black))

*********************
*End of replication code
*********************
